//
//  HomeVideoGuideView.swift
//  NDAi
//
//  Created by 丸子 on 2024/7/17.
//

import UIKit
let firstLaunchVideoGuideKey = "VideoGuideKey"

class HomeVideoGuideView: UIView {
    var nextGuideBag:( () -> Void)?

    private lazy var arrowIV: UIImageView = {
       let imageView = UIImageView()
        imageView.image = UIImage(named: "icon_home_chatJT")
        imageView.contentMode = .scaleToFill
        return imageView
    }()
    
    private lazy var tipsView: UIView = {
       let view = UIView()
        view.allRound(8)
        return view
    }()
    
    private lazy var tipsLb: UILabel = {
       let label = UILabel()
        label.textColor = .white
        label.text = "   点击广场视频，发现更多创意～   "
        label.font = UIFont.pingFangSCMedium(ofSize: 16)
        return label
    }()
    
    private lazy var notIV: UIImageView = {
       let imageView = UIImageView()
        imageView.image = UIImage(named: "icon_home_not")
        return imageView
    }()
    
    private lazy var okBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.normalTitle = "好的"
        button.titleColorForNormal = UIColor.white
        button.titleFont = UIFont.pingFangSCMedium(ofSize: 14)
        button.layer.borderWidth = 1
        button.layer.borderColor = UIColor.white.cgColor
        button.allRound(20)
        return button
    }()
    
    override init(frame: CGRect) {
        super.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
        self.backgroundColor = UIColor(hexString: "#000000", transparency: 0.8)
    
        
    }
    func initUI(rect:CGRect) {
        let y = navHig() + rect.origin.y + 20
        let height = (SCREEN_WIDTH - 52) / 2
        let transparentRect = CGRect(x: 10, y: y, width: SCREEN_WIDTH - 20, height: 82 + height)
        let maskLayer = CAShapeLayer()
        let path = UIBezierPath(rect: self.bounds)
        
        // 创建一个具有圆角的矩形路径
        let roundedRectPath = UIBezierPath(roundedRect: transparentRect, cornerRadius: 5)
        path.append(roundedRectPath.reversing())
        maskLayer.path = path.cgPath
        self.layer.mask = maskLayer
        
        self.addSubviews([arrowIV, tipsView, tipsLb, notIV, okBtn])
        
        arrowIV.snp.makeConstraints { make in
            make.top.equalTo(transparentRect.origin.y + (82 + height))
            make.leading.equalToSuperview().offset(52)
        }
        
        tipsLb.snp.makeConstraints { make in
            make.top.equalTo(arrowIV.snp.bottom).offset(10)
            make.leading.equalToSuperview().offset(16)
            make.height.equalTo(50)
        }
        
        tipsView.snp.makeConstraints { make in
            make.edges.equalTo(tipsLb)
        }
        
        notIV.snp.makeConstraints { make in
            make.bottom.equalTo(tipsView.snp.top).offset(18)
            make.trailing.equalTo(tipsLb.snp.trailing).offset(12)
        }
        
        okBtn.snp.makeConstraints { make in
            make.top.equalTo(tipsView.snp.bottom).offset(12)
            make.centerX.equalToSuperview()
            make.height.equalTo(40)
            make.width.equalTo(120)
        }
        
        okBtn.setClosureTouchUpInside_k { [weak self] in
            self?.nextGuideBag?()
            self?.removeFromSuperview()
        }
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        tipsView.themeGradient([UIColor(hexString: "#45C8FF"), UIColor(hexString: "#7BF7FF")], .leftToRight)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
